package com.ggqq.day315;
//力扣867
public class transposeMatrix {
    public static void main(String[] args){
        int[][] matrix ={{1,2,3},{4,5,6},{7,8,9}};
        transposeMatrix x = new transposeMatrix();
        int[][] trans = x.transpose(matrix);

        //遍历二维数组
        for(int i=0;i<trans.length;i++){
            for(int j=0;j<trans[0].length;j++){
                System.out.println(trans[i][j]);
            }
        }


    }
    public int[][] transpose(int[][] matrix){
        int m = matrix.length;
        int n = matrix[0].length;
        int[][] trans = new int[n][m];
        for(int i=0;i<m;i++){
            for(int j=0;j<n;j++){
                trans[j][i] = matrix[i][j];
            }
        }
        return  trans;
    }
}
